package com.example.demo.common.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.demo.common.entity.Role;
import com.example.demo.common.entity.User;
import com.example.demo.common.entity.UserPermission;
import com.example.demo.common.mapper.RoleMapper;
import com.example.demo.common.mapper.UserMapper;
import com.example.demo.common.mapper.UserPermissionMapper;
import com.example.demo.common.service.UserService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController
@RequestMapping("/common/user")
public class UserWeb {


    @Autowired
    UserService userService;
    @Autowired
    RoleMapper roleMapper;
    @Autowired
    UserPermissionMapper userPermissionMapper;
    @Autowired
    UserMapper userMapper;
    
    @RequestMapping("/getusers")
    public Object getusers(){
    	/*Wrapper<User> wp=new EntityWrapper<>();
    	wp.eq("username", "1");
    	Map<String, Object> map=new HashMap<>();
    	map.put("username", "1");
    	wp.and("username={0}","1");
    	List<User> lists=userService.selectList(wp);
    	lists=userMapper.selectAll(); 
    	String sql="and username=#{map.username}";
    	String sql="and username=#{searchParam.username}";
    	lists=userMapper.selectBySql(sql);
    	Page<User> page=new Page<>();
    	page.setSize(2);
    	page.setCurrent(1); */
    	Map< String, Object> searchParam=new HashMap<>();
    	searchParam.put("username", "1");
    	List<User> lists=userService.selectBySeachParam(searchParam);
    	
    	Map< String, Object> roleColumnMap=new HashMap<>();
    	roleColumnMap.put("role_name", "manager");
    	Set<String> roles = roleMapper.getRole("1");
    	
    	//return null;
        return roles;
    }
    
    @RequestMapping("/getusers2")
    public Object getusers2(Map< String, Object> searchParam,Page page){
    	
    	List<User> lists=userService.selectBySeachParam(searchParam,page);
    	Map< String, Object> roleColumnMap=new HashMap<>();
    	roleColumnMap.put("role_name", "manager");
    	Set<String> roles = roleMapper.getRole("1");

    	Map< String, Object> results=new HashMap<>();
    	results.put("java_table_name", roleColumnMap);
    	results.put("page", page);
    	//return null;
        return results;
    }
    
    @RequestMapping("/login")
    public Object login() {
    	
        return ("用户名或者密码错误");
    }

}
